/*
 * Functions.java
 *
 * Created on September 7, 2007, 10:31 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package util;

import java.awt.Component;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 *
 * @author user
 */
public class Functions {
   public static void clearForm(Component c)
   {
        
    }
    
   
   public static boolean copyFolder(String source, String destin)
   {
      try
      {
         File files =  new File(source);
      
         for(File file : files.listFiles())
            copyFile(source+file.getName(), destin+file.getName());
         return true;
      }
      catch(Exception e)
      {
         return false;
      }
   }
   /**
    * Copia arquivos fisicamente
    * @param  inFile  Caminho completo do arquivo de origem
    * @param  outFile Caminho completo do arquivo de destino
    * @return true se a cópia do arquivo for realizada com sucesso
    */
   public static boolean copyFile(String inFile, String outFile) {
      InputStream is = null;
      OutputStream os = null;
      byte[] buffer;
      boolean success = true;
      try {
         is = new FileInputStream(inFile);
         os = new FileOutputStream(outFile);
         buffer = new byte[is.available()];
         is.read(buffer);
         os.write(buffer);
      } catch (IOException e) {
         success = false;
      } catch (OutOfMemoryError e) {
         success = false;
      } finally {
         try {
            if (is != null) {
               is.close();
            }
            if (os != null) {
               os.close();
            }
         } catch (IOException e) {}
      }
      return success;
   }    
}
